<?php

namespace App\Http\Services;

class PicUrlService
{
    static public function getPicUrl($pic_url)
    {
        if (empty($pic_url)) {

            return $pic_url;
        }

        return self::getPicUrlNotEmpty($pic_url);
    }

    static private function getPicUrlNotEmpty($pic_url)
    {
        $admin_config_upload = config('admin.upload');
        switch ($admin_config_upload['disk']) {
            case 'oss':

                return "http://" . env('OSS_BUCKET') . "." . env('OSS_ENDPOINT') . "/" . $pic_url;
                break;
            default:

                return $pic_url;
        }
    }

    static public function getVideoPicUrl($pic_url, $video_url = null)
    {
        if (empty($pic_url)) {

            return self::getVideoPicUrlEmpty($pic_url, $video_url);
        } else {

            return self::getPicUrlNotEmpty($pic_url);
        }
    }

    static private function getVideoPicUrlEmpty($pic_url, $video_url = null)
    {
        $admin_config_upload = config('admin.upload');
        switch ($admin_config_upload['disk']) {
            case 'oss':
                if (!empty($video_url)) {
                    $t = rand(0, 180000);

                    return $video_url . "?x-oss-process=video/snapshot,t_" . $t . ",f_jpg,w_380,h_280";
                }
                break;
            default:

                return $pic_url;
        }
    }
}
